package cn.bdqn.pn.controller.base;

import cn.bdqn.pn.pojo.base.Question;

import cn.bdqn.pn.pojo.base.Reply;
import cn.bdqn.pn.service.base.QuestionService;
import cn.bdqn.pn.service.base.ReplyService;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;


import java.util.List;

@Controller
@RequestMapping("/questions")
public class QuestionController {


    @Autowired
    private QuestionService questionService;
    @Autowired
    private ReplyService replyService;

    /**
     * 展示所有问题
     */
    @RequestMapping("/aa")
    public String a(Model model)throws Exception {
        List<Question> questionList=questionService.showQuestion();
        model.addAttribute("questionList",questionList);
        System.out.println(JSON.toJSONString(questionList,true));
        return "/Questionquestion";
    }
  /*  @RequestMapping("/zengjia")
    public String zengjia(Reply reply){
        replyService.addReply(reply);
        return "/Questionquestion";
    }*/
    /**
     * 给问题回复
     * @param reply
     * @return
     * @throws Exception
     */
  @RequestMapping("/zengjia")
    public String add(Reply reply,Model model) throws Exception {
        replyService.addReply(reply);
      List<Question> questionList=questionService.showQuestion();
      model.addAttribute("questionList",questionList);
        return  "/Questionquestion";
    }
}
